home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7573 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is &Variable (declared as: char Variable[10])?
  5. Date: Tue, 27 Feb 1996 14:50:18 GMT
  6. Organization: Netcom
  7. Message-ID: <313318b8.53776146@nntp.ix.netcom.com>
  8. References: <4gqpa1$3h9@alcor.usc.edu> <4gsdno$1bg@umbc9.umbc.edu> <4gtab6$acb@ceylon.gte.com>
  9. NNTP-Posting-Host: ix-dc12-08.ix.netcom.com
  10. X-NETCOM-Date: Tue Feb 27  6:50:08 AM PST 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. Brenda <g051286> wrote:
  14.  
  15. > schlein@umbc.edu (Jonas J. Schlein) wrote:
  16. > >Abu Wawda <wawda@alcor.usc.edu> wrote:
  17. > >|> I'm having trouble understanding what the address of a static array
  18. > >|> is.
  19. > >
  20. > >I'm having trouble understanding why it matters? You almost never use the
  21. > >address of an array directly unless doing something tricky with pointers
  22. > >or with particular dimensions of a multiple dimensional array.
  23. > >
  24. > >|> For example, if I declare a variable called myarray as:
  25. > >|>     char myarray[10];
  26. > >|> then what could &myarray possibly mean? myarray is not a pointer, so
  27. > >|> &myarray could not possibly be the address of the variable myarray
  28. > >|> (like it would be if I did char* myarray and then asked for &myarray).
  29. > >
  30. > >Yes it could and yes it is...'myarray' is not a pointer, but &myarray is
  31. > >a pointer to 'myarray'.
  32. > Um, that's not correct.  myarray is DEFINITELY a pointer!  As declared above,
  33. > it is a constant pointer to 10 contiguous char datatypes.  myarray is an
  34. > ADDRESS whereas *(myarray + 5) or myarray[5] is the 6th element in the array.
  35. > The difference between an array and something like "char *p=myarray", is that
  36. > you can say p++, but you can't say myarray++.  You shouldn't say &myarray
  37. > either because myarray is a constant, but I read that on some compilers
  38. > scanf ignores the dereferencing and does not bother to warn you.
  39.  
  40. NO. NO. NO.  Where do people get this idea that arrays are pointers.
  41. Arrays are arrays and pointers are pointers.  In many, but not all,
  42. situations an array is converted to a pointer.  There are exceptions.
  43. For example sizeof myarray is 10 but sizeof p is almost certainly not
  44. 10.
  45.  
  46. Why shouldn't you say &myarray.  It's perfectly legal C and any
  47. compiler that does not accept it is broken.  &myarray is a pointer to
  48. an array of 10 char.
  49.  
  50.  
  51. Michael M Rubenstein
  52.